const mongoose = require('./mongooseConnection');

// 定义一个简单的模型
const UserSchema = new mongoose.Schema({
    name: String,
    age: Number
});

const User = mongoose.model('User', UserSchema);

async function main() {
    try {
        // 创建一个新用户
        const newUser = new User({ name: 'John', age: 30 });
        const savedUser = await newUser.save();
        console.log('保存的用户:', savedUser);

        // 查询所有用户
        const users = await User.find({});
        console.log('所有用户:', users);
    } catch (error) {
        console.error('操作数据库时出错:', error);
    } finally {
        // 关闭数据库连接
        await mongoose.connection.close(); 
    }
}

main();
